package cn.tedu.ykmall.admin.commodity.webapi.controller;

import cn.tedu.ykmall.admin.commodity.service.ICategoryService;
import cn.tedu.ykmall.common.web.JsonResult;
import cn.tedu.ykmall.pojo.commodity.dto.AdminCategoryByDepthDTO;
import cn.tedu.ykmall.pojo.commodity.vo.AdminCategoryTwoByDepthVO;
import cn.tedu.ykmall.pojo.commodity.vo.CategoryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.swing.*;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping(value = "/category",produces = "application/json;charset=utf-8")
public class CategoryController {
    @Autowired
    private ICategoryService service;

    @PostMapping("/insertOne")
    public void insertOneCategory(@RequestBody CategoryVO categoryVO){
        service.insertOneCategory(categoryVO);
    }

    @GetMapping("/selectOneByDepth")
    public JsonResult<List<AdminCategoryByDepthDTO>> selectOneByDepth(){
        List<AdminCategoryByDepthDTO> list = service.selectCategoryByDepth(1);
        return JsonResult.ok(list);
    }

    @GetMapping("/selectTwoByDepth")
    public JsonResult<List<AdminCategoryTwoByDepthVO>> selectTwoByDepth(){
        List<AdminCategoryTwoByDepthVO> voList = service.selectCategoryByParentId();
        return JsonResult.ok(voList);
    }
}
